<template>
    <div class="form-main-content">
        <a-table :columns="columns" :dataSource="data" rowKey="id" :pagination="pagination" bordered>
            <template slot="task" slot-scope="text, record">
                <router-link :to="'/task/update/'+record.task_id">
                    {{record.order_name}}<p>{{record.task_sn}}</p>
                </router-link>
            </template>
            <template slot="action" slot-scope="text, record">
                <!-- <router-link :to="'/report/update/'+record.id"><img src="./../../assets/images/view.svg" alt="">
                </router-link> -->
                
                <a-button type="primary" @click="exports(record.id)">导出</a-button>
                <a @click.stop.prevent="del(record)" class="delete-image" v-if="user_id == dispatch_id"><img
                        src="./../../assets/images/delete.svg" alt=""></a>
                <router-link :to="'/orders/particulars/'+record.id" >
                    <img src="../../assets/images/view.svg" alt="">
                </router-link>
            </template>
        </a-table>
    </div>
</template>

<script>
    import qs from "qs"
    export default {
        name: 'report',
        props: ['task_id', 'dispatch_id','user_id'],
        data() {
            return {
                pagination: {
                    current: 1,
                    total: 0,
                    pageSize: 10,
                    showQuickJumper: true,
                    onChange: (page, size) => {
                        this.handleChange(page, size)
                    },
                },
                columns: [
                    {title: '报告名称', dataIndex: 'name', align: 'center'},
                    {title: '生成时间', dataIndex: 'created_at', align: 'center'},
                    {title: '标注数量', dataIndex: 'num', align: 'center'},
                    {title: '操作', scopedSlots: {customRender: 'action'}, align: 'center'},
                ],
                data: [],
            }
        },
        methods: {
            async getList(param = {}) {
                let req = {page_size: this.pagination.pageSize, page: this.pagination.current, task_id: this.task_id};

                let data = await this.http(
                    "get",
                    "report/index",
                    {...req, ...param}
                );
                this.data = data.data;
                this.pagination.total = data.total_count;
            },
            del(data) {
                var that = this;
                this.$confirm({
                    title: '删除报告',
                    content: '是否删除此报告:' + data.order_name + data.task_sn,
                    onOk() {
                        that.http("delete", "report/delete", {id: data.id}).then(res => {
                            if (res.code == 200) {
                                that.$message.success(res.msg);
                                that.getList();
                            } else {
                                that.$message.error(res.msg);
                            }
                        });
                    },
                    onCancel() {
                    },
                });
            },
            exports(id){
                let  params = {status:0,export:1,selects:id}
                open(process.env.VUE_APP_BASE_URL+'report/export?'+qs.stringify(params),'_blank')
            }
        
        },
        mounted() {
            this.getList();
        },
    }
</script>
